<?php 

function is_pjax(){
    return array_key_exists('HTTP_X_PJAX', $_SERVER) && $_SERVER['HTTP_X_PJAX'];
}


$step2Html ='<div class="row">
	<div class="col-xs-4">
		设置账号2
	</div>
	<div class="col-xs-4">
		账户信息设置
	</div>
	<div class="col-xs-4">
		注册完成
	</div>
</div>
<div class="row">
	<form action="/pjax/register.php?method=finish" data-pjax="true" method="post" id="register_form">
		<div class="col-xs-offset-2 col-xs-10">
			<div class="row">
				<div class="col-xs-4">
					工作单位
				</div>
				<div class="col-xs-8">
					<input type="text" class="form-control" name="orgnization" placeholder="请输入工作单位"/>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-4">
					所属部门
				</div>
				<div class="col-xs-8">
					<input type="text" class="form-control" name="verify" placeholder="请输入您所在的部门"/>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-4">
					邮箱
				</div>
				<div class="col-xs-8">
					<input type="text" class="form-control" name="email" placeholder="邮箱"/>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-4">
					昵称
				</div>
				<div class="col-xs-8">
					<input type="text" class="form-control" name="nickname" placeholder="起个让人印象深刻的昵称吧"/>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-4">
					密码
				</div>
				<div class="col-xs-8">
					<input type="text" class="form-control" name="password" placeholder="请设置密码"/>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-4">
				
				</div>
				<div class="col-xs-4">
					<button type="submit" class="btn btn-default">下一步</button>
				</div>
				<div class="col-xs-4">
					
				</div>
			</div>
		</div>
	</form>
</div>';

$finishHtml ='<div class="row">
	<div class="col-xs-4">
		设置账号2
	</div>
	<div class="col-xs-4">
		账户信息设置
	</div>
	<div class="col-xs-4">
		注册完成
	</div>
</div>
<div class="row">
		<div class="col-xs-4">
		</div>
		<div class="col-xs-4">
			恭喜注册完成
		</div>
		<div class="col-xs-4">
		</div>
</div>';


function step2(){
	Global $step2Html;
	if(!checkStep2()){
		http_response_code(401);
		exit(json_encode(['xxx'=>'xxx不能为空']));
	}
	exit($step2Html);
}

function finish(){
	Global $finishHtml;
	if(!checkStep3()){
		http_response_code(401);
		exit(json_encode(['xxx'=>'xxx不能为空']));
	}
	exit($finishHtml);
}

function checkStep2(){
	return true;
}

function checkStep3(){
	return true;
}

$_method = $_REQUEST['method'];

if(is_pjax()){
	if($_method=="step2" || $_method=="finish"){
		$_method();
	}else{
		http_response_code(404);
		exit(json_encode(['error'=>'请求存在']));
	}
}else{
	header("location: http://localhost/pjax/");//or rendor full html
}
